<?php
namespace app\admin\controller;
class Login extends \think\Controller
{
    public function index(){
        if(!session(Basic::SESSION_AUTH_KEY)){
            return $this->fetch();
        }else{
            $this->redirect('/admin/Index/main.html');
        }
    }
    
    public function login(){
        $V = \think\Loader::model('User','logic');
        
        $account = \think\Request::instance()->post('acount');
        $passWord = \think\Request::instance()->post('password');
        
        if(!$V->isAdmin($account,$passWord)){
            return $this->error('密码或帐号错误！');
        }
        
        session(Basic::SESSION_AUTH_KEY,$account);
      
        $this->redirect("/admin/Index/main.html");
        
    }
    
    public function layout(){
        session(Basic::SESSION_AUTH_KEY,false);
        $this->redirect('admin/index/index');
    }
    public function AddAdmin(){
        $account = \think\Request::instance()->post('acount');
        $passWord = \think\Request::instance()->post('password');
        
        $V = \think\Loader::model('User','logic');
        $V->addAdmin($account,$passWord);
        
        $this->redirect('/admin/index/index');
    }


    public function register(){
        return $this->fetch();
    }
}